package core

import (
	"bytes"
	"merkletree"
)

type Transaction struct {
	Source      []byte
	Destination []byte
	Index       uint64
	Timestamp   uint64
	Amount      uint64
	Gas         uint64
	HashMethod  uint64
	Hash        []byte
	Signature   []byte
}

//这个计算Hash并不作为真正的Hash计算 因为这是固定的接口 不能进行Hash函数的选择
//真正的计算Hash的函数另有定义
func (t Transaction) CalculateHash() ([]byte, error) {
	return t.Hash, nil
}

func (t Transaction) Equals(other merkletree.Content) (bool, error) {
	if bytes.Equal(t.Source, other.(Transaction).Source) == false {
		return false, nil
	}
	if bytes.Equal(t.Destination, other.(Transaction).Destination) == false {
		return false, nil
	}
	if t.Index != other.(Transaction).Index {
		return false, nil
	}
	if t.Timestamp != other.(Transaction).Timestamp {
		return false, nil
	}
	if t.Amount != other.(Transaction).Amount {
		return false, nil
	}
	if t.Gas != other.(Transaction).Gas {
		return false, nil
	}
	if t.HashMethod != other.(Transaction).HashMethod {
		return false, nil
	}
	if bytes.Equal(t.Hash, other.(Transaction).Hash) == false {
		return false, nil
	}
	if bytes.Equal(t.Signature, other.(Transaction).Signature) == false {
		return false, nil
	}
	return true, nil
}
